package org.budo.solr.jdbc.driver;

import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import org.budo.jdbc.driver.AbstractBudoJdbcConnection;
import org.budo.jdbc.driver.parser.SqlStatementParser;
import org.budo.jdbc.driver.statement.JdbcStatement;

/**
 * @author lmw
 */
public class BudoSolrJdbcConnection extends AbstractBudoJdbcConnection {
    private SqlStatementParser statementParser;

    private boolean closed = false;

    @Override
    public PreparedStatement prepareStatement(String sql) throws SQLException {
        SqlStatementParser statementParser = this.getStatementParser();
        JdbcStatement jdbcStatement = statementParser.parse(sql);

        BudoSolrJdbcPreparedStatement preparedStatement = new BudoSolrJdbcPreparedStatement();
        preparedStatement.setConnection(this);
        preparedStatement.setJdbcStatement(jdbcStatement);
        return preparedStatement;
    }

    @Override
    public Statement createStatement() throws SQLException {
        BudoSolrJdbcStatement statement = new BudoSolrJdbcStatement();
        statement.setConnection(this);
        return statement;
    }

    @Override
    public void setAutoCommit(boolean autoCommit) throws SQLException {}

    @Override
    public boolean getAutoCommit() throws SQLException {
        return true;
    }

    @Override
    public void close() throws SQLException {
        this.closed = true;
    }

    @Override
    public boolean isClosed() throws SQLException {
        return this.closed;
    }

    @Override
    public DatabaseMetaData getMetaData() throws SQLException {
        return null;
    }

    @Override
    public void setReadOnly(boolean readOnly) throws SQLException {}

    @Override
    public boolean isReadOnly() throws SQLException {
        return false;
    }

    @Override
    public String getCatalog() throws SQLException {
        return null;
    }

    @Override
    public int getTransactionIsolation() throws SQLException {
        return 0;
    }

    @Override
    public void clearWarnings() throws SQLException {}

    @Override
    public int getHoldability() throws SQLException {
        return 0;
    }

    public SqlStatementParser getStatementParser() {
        return this.statementParser;
    }

    public void setStatementParser(SqlStatementParser statementParser) {
        this.statementParser = statementParser;
    }
}